<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>

      </template>
      <!--操作栏-->
      <template #action="{ record }">
        <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
      </template>
      <!--字段回显插槽-->
      <template #htmlSlot="{text}">
        <div v-html="text"></div>
      </template>
      <!--省市区字段回显插槽-->
      <template #pcaSlot="{text}">
        {{ getAreaTextByCode(text) }}
      </template>
      <template #fileSlot="{text}">
        <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
        <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small"
          @click="downloadFile(text)">下载</a-button>
      </template>
    </BasicTable>
    <!-- 表单区域 -->
    <TSubmissionModal @register="registerModal" @success="handleSuccess"></TSubmissionModal>
    <TInspectionModal @register="registerModal2" @success="handleSuccess"></TInspectionModal>
    <Desc @register="registerDesc"></Desc>
  </div>
</template>

<script lang="ts" name="TSubmission-tSubmission" setup>
  import { ref, computed, unref } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useModal } from '/@/components/Modal';
  import { useListPage } from '/@/hooks/system/useListPage'
  import TSubmissionModal from './components/TSubmissionModal.vue'
  import TInspectionModal from '../TInspection/components/TInspectionModal.vue'
  import Desc from "./components/Desc.vue";
  import { columns, searchFormSchema } from './TSubmission.data';
  import { list2, deleteOne, batchDelete, getImportUrl, getExportUrl, checkOne } from './TSubmission.api';
  import { downloadFile } from '/@/utils/common/renderUtils';

  const [registerDesc, { openModal: openDescInfo }] = useModal();
  //注册model
  const [registerModal, { openModal }] = useModal();
  const [registerModal2, modalFunc] = useModal();
  //注册table数据
  const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
    tableProps: {
      title: '待检表',
      api: list2,
      searchInfo: {},
      columns,
      canResize: false,
      formConfig: {
        //labelWidth: 120,
        schemas: searchFormSchema,
        autoSubmitOnEnter: true,
        showAdvancedButton: true,
        fieldMapToNumber: [
        ],
        fieldMapToTime: [
        ],
      },
      actionColumn: {
        width: 200,
        fixed: 'right'
      },
    },
    exportConfig: {
      name: "待检表",
      url: getExportUrl,
    },
    importConfig: {
      url: getImportUrl,
      success: handleSuccess
    },
  })

  const [registerTable, { reload }, { rowSelection, selectedRowKeys }] = tableContext

  /**
    * 新增报告
    */
  function handleAddReport(record : Recordable) {
    modalFunc.openModal(true, {
      isUpdate: false,
      showFooter: true,
      submissionId: record.id
    });
  }
  /**
   * 详情
  */
  function handleDetail(record : Recordable) {
    openDescInfo(true, {
      record,
      isUpdate: true,
      showFooter: false,
    });
  }
  /**
   * 成功回调
   */
  function handleSuccess() {
    (selectedRowKeys.value = []) && reload();
  }
  /**
     * 操作栏
     */
  function getTableAction(record) {
    var tableAction = []
    if (record.status == 20) {
      tableAction.push({
        label: '添加检测结论',
        onClick: handleAddReport.bind(null, record),
      })
    }
    return tableAction;
  }
  /**
     * 下拉操作栏
     */
  function getDropDownAction(record) {
    var tableAction = [
      {
        label: '详情',
        onClick: handleDetail.bind(null, record),
      }
    ]
    return tableAction
  }
</script>

<style scoped>

</style>
